package com.appoint.buss.service.impl;

import java.util.List;

import com.alibaba.fastjson2.util.UUIDUtils;
import com.appoint.buss.domain.EpiparaChipInfo;
import com.appoint.buss.domain.req.EpiparaChipSeqReqVO;
import com.appoint.buss.domain.vo.EpiparaChipSeqRespVO;
import com.appoint.buss.mapper.EpiparaChipInfoMapper;
import com.appoint.buss.service.AsyncChipSeqService;
import com.appoint.common.exception.ServiceException;
import com.appoint.common.utils.StringUtils;
import com.appoint.common.utils.uuid.IdUtils;
import com.appoint.common.utils.uuid.UUID;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.appoint.buss.mapper.EpiparaChipSeqMapper;
import com.appoint.buss.domain.EpiparaChipSeq;
import com.appoint.buss.service.IEpiparaChipSeqService;

import javax.annotation.Resource;

/**
 * epipara_chip_seqService业务层处理
 *
 * @author appoint
 * @date 2023-01-15
 */
@Service
public class EpiparaChipSeqServiceImpl  extends ServiceImpl<EpiparaChipSeqMapper,EpiparaChipSeq> implements IEpiparaChipSeqService
{
    @Resource
    private EpiparaChipSeqMapper epiparaChipSeqMapper;

    @Autowired
    private AsyncChipSeqService asyncChipSeqService;

    @Resource
    private EpiparaChipInfoMapper epiparaChipInfoMapper;

    /**
     * 查询epipara_chip_seq
     *
     * @param id epipara_chip_seq主键
     * @return epipara_chip_seq
     */
    @Override
    public EpiparaChipSeq selectEpiparaChipSeqById(String id)
    {
        return epiparaChipSeqMapper.selectById(id);
    }

    /**
     * 查询epipara_chip_seq列表
     *
     * @param epiparaChipSeq epipara_chip_seq
     * @return epipara_chip_seq
     */
    @Override
    public List<EpiparaChipSeq> selectEpiparaChipSeqList(EpiparaChipSeq epiparaChipSeq)
    {
        return epiparaChipSeqMapper.selectEpiparaChipSeqList(epiparaChipSeq);
    }

    /**
     * 新增epipara_chip_seq
     *
     * @param epiparaChipSeq epipara_chip_seq
     * @return 结果
     */
    @Override
    public int insertEpiparaChipSeq(EpiparaChipSeq epiparaChipSeq)
    {
        epiparaChipSeq.setId(IdWorker.getIdStr());
        return epiparaChipSeqMapper.insertEpiparaChipSeq(epiparaChipSeq);
    }

    /**
     * 修改epipara_chip_seq
     *
     * @param epiparaChipSeq epipara_chip_seq
     * @return 结果
     */
    @Override
    public int updateEpiparaChipSeq(EpiparaChipSeq epiparaChipSeq)
    {
        return epiparaChipSeqMapper.updateEpiparaChipSeq(epiparaChipSeq);
    }

    /**
     * 批量删除epipara_chip_seq
     *
     * @param ids 需要删除的epipara_chip_seq主键
     * @return 结果
     */
    @Override
    public int deleteEpiparaChipSeqByIds(Long[] ids)
    {
        return epiparaChipSeqMapper.deleteEpiparaChipSeqByIds(ids);
    }

    /**
     * 删除epipara_chip_seq信息
     *
     * @param id epipara_chip_seq主键
     * @return 结果
     */
    @Override
    public int deleteEpiparaChipSeqById(Long id)
    {
        return epiparaChipSeqMapper.deleteEpiparaChipSeqById(id);
    }

    @Override
    public String importUser(List<EpiparaChipSeq> list, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(list) || list.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }
        String resultMsg = "恭喜您，数据已全部导入成功！共 " + list.size() + " 条";
        try {
            asyncChipSeqService.saveChipSeq(list);
        } catch (Exception e) {
            resultMsg  = "很抱歉，导入失败！";
            log.error(resultMsg, e);
        }
        return resultMsg;
    }

    @Override
    public List<EpiparaChipSeqRespVO> list2(EpiparaChipSeqReqVO reqVO) {
        return epiparaChipSeqMapper.list2(reqVO);
    }

    @Override
    public void hhh() {
        QueryWrapper<EpiparaChipSeq> queryWrapper = new QueryWrapper<>();
        List<EpiparaChipSeq> list = epiparaChipSeqMapper.selectList(queryWrapper);
        for (int i = 0; i < list.size(); i++) {
            EpiparaChipSeq epiparaChipSeq = list.get(i);
            String url = epiparaChipSeqMapper.hhh(epiparaChipSeq.getId());
            EpiparaChipInfo epiparaChipInfo = new EpiparaChipInfo();
            epiparaChipInfo.setBrowser(url);
            QueryWrapper<EpiparaChipInfo> wrapper = new QueryWrapper<>();
            wrapper.eq("seq_id",epiparaChipSeq.getId());
            epiparaChipInfoMapper.update(epiparaChipInfo,wrapper);
        }
    }
}
